declare
fun {NewPortObject Init Fun}
Sin Sout in
   thread {FoldL Sin Fun Init Sout} end
   {NewPort Sin}
end


fun {FoldL L F U}
   case L
   of nil then U
   [] X|L2 then
      {FoldL L2 F {F U X}}
   end
end


fun {NewPortObject2 Proc}
   Sin in
   thread for Msg in Sin do {Proc Msg} end end
   {NewPort Sin}
end